#include "levelobjectselectionmanager.h"
#include "abstractlevelobject.h"
#include "level.h"

using namespace LevelObjects;

LevelObjectSelectionManager::LevelObjectSelectionManager(QObject *parent)
	: QObject(parent)
{

}

void LevelObjects::LevelObjectSelectionManager::select( QPointer<AbstractLevelObject> lo )
{
	if(!isSelected(lo))
	{
		m_selection << lo;
		emit objectSelectionChanged();
	}
}

void LevelObjects::LevelObjectSelectionManager::select( QList<QPointer<AbstractLevelObject> > loList )
{
	if(!selection().isEmpty())
	{
		deselectAll();
	}
	
	m_selection << loList;

	emit objectSelectionChanged();
}

void LevelObjects::LevelObjectSelectionManager::deselect( QPointer<AbstractLevelObject> lo )
{
	if(isSelected(lo))
	{
		m_selection.removeOne(lo);
		emit objectSelectionChanged();
	}
}

void LevelObjects::LevelObjectSelectionManager::selectAll()
{

}

void LevelObjects::LevelObjectSelectionManager::deselectAll()
{
	if(m_selection.size())
	{
		m_selection.clear();
		emit objectSelectionChanged();
	}
}

bool LevelObjects::LevelObjectSelectionManager::isSelected( QPointer<AbstractLevelObject> lo )
{
	return m_selection.contains(lo);
}

Level& LevelObjects::LevelObjectSelectionManager::level()
{
	QPointer<Level> level = qobject_cast<Level*>(parent());
	Q_ASSERT(level);
	return *level;
}

const LevelObjectSelectionManager::Selection& LevelObjects::LevelObjectSelectionManager::selection() const
{
	return m_selection;
}
